package awl;

import static org.junit.Assert.assertTrue;
import awl.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Test Xinetd's bullet has hit a single victim during the battle.
 * Xinetd should be have a tracking mechanism in play.
 * 
 * @author Alan Lee
 */
public class TestXinetdHitVictim extends RobotTestBed {
  /** True if the robot hit a robot during the test case. */
  boolean hitEnemy = false;
  double energy = 0.0;

  /**
   * Specifies that Crazy and Xinetd are to be matched up in this test case.
   * 
   * @return A comma-delimited list of robots in this match
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,awl.Xinetd";
  }
  
  /**
   * This test runs for a round.
   * 
   * @return The number of rounds in this test 
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * After each turn, check to see if Xinetd fire at robot.
   * If so, set flag.
   * 
   * @param event Information about the current state of the battle
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    energy = robot.getEnergy();
    if (energy < 85.0) {
      hitEnemy = true;
    }
  }
  
  /**
   * Asserts that Xinetd fire at enemy and is ramming it.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    
    assertTrue("Hit Robot", hitEnemy);
  }
  
  /**
   * Returns false, thus making the robots always start at a random position each time.
   * 
   * @return False if the battle will not be deterministic, true otherwise
   */
  @Override
  public boolean isDeterministic() {
    return false;
  }
  
}
